home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / hypergraphConnectionEndMenu. < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.9 KB  |  129 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17.  
  18. global proc int hypergraphConnectionEndMenu(string $editor, string $menu,
  19.     string $node, string $plugName, string $direction, string $type,
  20.     string $disconnectPlug)
  21. //
  22. //    Description:
  23. //        Called to complete a connection when using the popup connection
  24. //        editing capability in the Hypergraph and Hypershade.  It is
  25. //        passed the source plug for the connection and direction so the
  26. //        popup menu that is built only shows attributes that are compatible
  27. //        with the source plug
  28. //
  29. {
  30.     string $title;
  31.     string $attrCmd;
  32.     string $cmd;
  33.  
  34.     if($direction == "from") {
  35.         $title            = "Inputs";
  36.         $attrCmd        = "attributeMenu -inputs "+$node+" -attrType "+$type;
  37.     }else{
  38.         $title            = "Outputs";
  39.         $attrCmd        = "attributeMenu -outputs "+$node+" -attrType "+$type;
  40.     }
  41.     int       $numElements = 2;
  42.  
  43.     string $nodeFrom;
  44.     string $nodeTo;
  45.     string $attrs[] = `eval $attrCmd`;
  46.     if($direction == "from") {
  47.         $nodeFrom    = $plugName;
  48.     }else{
  49.         $nodeTo        = $plugName;
  50.     }
  51.     int $postMenu;
  52.     int $length = size($attrs);
  53.     if($length == $numElements) {
  54.         if($direction == "from") {
  55.             $nodeTo        = $node+"."+$attrs[0];
  56.         }else{
  57.             $nodeFrom    = $node+"."+$attrs[0];
  58.         }
  59.         string $plug = `connectionInfo -sfd $nodeTo`;
  60.         if($plug != "") {
  61.             disconnectAttr $plug $nodeTo;
  62.         }
  63.         if(!`isConnected $nodeFrom $nodeTo`) {
  64.             connectAttr $nodeFrom $nodeTo;
  65.         }
  66.         $postMenu = 0;
  67.     }else if($length != 0) {
  68.         setParent -m $menu;
  69.         popupMenu -e -deleteAllItems $menu;
  70.         menuItem -l $title;
  71.         menuItem -divider true;    
  72.         string $dis;
  73.         if($direction == "from") {
  74.             $nodeTo        = $node;
  75.         }else{
  76.             $nodeFrom    = $node;
  77.             string $plug = `connectionInfo -sfd $nodeTo`;
  78.             if($plug != "") {
  79.                 $dis = "disconnectAttr "+$plug+" "+$nodeTo+";";
  80.             }
  81.         }
  82.         string    $newPlug;
  83.         int        $i = 0;
  84.         for ($i = 0 ; $i < $length ; $i += $numElements) {
  85.             string $name = $attrs[$i];
  86.             int $italicize    = ($attrs[$i+1] == "Connected"); 
  87.  
  88.             //  Attribute is a source and node is the destination
  89.             //
  90.             if($direction == "from") {
  91.                 $dis = "";
  92.  
  93.                 // If moving an existing connection then disconnect the old one
  94.                 // This is the more common left to right connection
  95.                 //
  96.                 if($disconnectPlug != "") {
  97.                     $dis = "disconnectAttr "+$nodeFrom+" "+$disconnectPlug+";";
  98.                 }
  99.  
  100.                 // If connecting to an already connected input then remove
  101.                 // its existing connection to avoid a fan in
  102.                 //
  103.                 $newPlug    = $nodeTo+"."+$attrs[$i];
  104.                 string $plug = `connectionInfo -sfd $newPlug`;
  105.                 if($plug != "") {
  106.                     $dis = $dis + "disconnectAttr "+$plug+" "+$newPlug+";";
  107.                 }
  108.  
  109.                 // Build the menu item with the command
  110.                 //
  111.                 menuItem -l $attrs[$i]
  112.                     -italicized $italicize -boldFont $italicize
  113.                      -c ($dis+"connectAttr "+$nodeFrom+" "+$newPlug);
  114.  
  115.             // Attribute is a destination and node is the source.
  116.             // This is the less common right to left connection
  117.             //
  118.             }else{
  119.                 $newPlug    = $nodeFrom+"."+$attrs[$i];
  120.                 menuItem -l $attrs[$i]
  121.                     -italicized $italicize -boldFont $italicize
  122.                     -c ($dis+"connectAttr "+$newPlug+" "+$nodeTo);
  123.             }
  124.         }
  125.         $postMenu = 1;
  126.     }
  127.     return $postMenu;
  128. }
  129.